package com.tzbank.face.controller;

import com.tzbank.face.entity.FaceModel;
import com.tzbank.face.service.FaceService;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api("TZBANK-AI:刷脸认证控制器")
@RestController
public class FaceController {

	@Autowired
	FaceService faceService;

	/**
	 * 初始化认证
	 * 
	 * @param vo
	 * @return
	 * @auther llz&wdj 2018/05/17
	 * @throws InterruptedException
	 */
	@ApiOperation(value = "intoface", notes = "认证初始化--->[metainfo]该参数为必填项，其他参数暂时不需要填写！！")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "metainfo", value = "metainfo 环境参数，需要通过客户端 SDK 获取", paramType = "query", required = true),
			@ApiImplicitParam(name = "certNo", value = "身份证号", paramType = "query"),
			@ApiImplicitParam(name = "certName", value = "身份证名字", paramType = "query"),
			@ApiImplicitParam(name = "userId", value = "用户id", paramType = "query" ,required = true ),
			@ApiImplicitParam(name = "requestSource", value = "请求来源", paramType = "query" ,required = true )})
	@RequestMapping(value = "/intoface", method = { RequestMethod.POST })
	@ResponseBody
	public Map<String, Object> initialize(@RequestBody FaceModel vo) {

		if (vo.getMetainfo() == null) {
			return ResultUtil.resultMap(CodeUtil.CODE_10000.getName() + ":设备信息为空", CodeUtil.CODE_10000.getCode(), null);
		} else if (StringUtils.isEmpty(vo.getCertName()) || StringUtils.isEmpty(vo.getCertNo())) {
			return ResultUtil.resultMap(CodeUtil.CODE_10000.getName() + ":证件信息为空", CodeUtil.CODE_10000.getCode(), null);
		}
		return faceService.intoFaceService(vo);
	}

	/**
	 * 认证确认
	 * 
	 * @auther llz&wdj 2018/05/17
	 * @throws InterruptedException
	 */
	@ApiOperation(value = "queryFace", notes = "认证结果查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "bizId", value = "接入方请求的唯一标识，由字母、数字、下划线组成，商户须确保其唯一性。", paramType = "query", required = true),
			@ApiImplicitParam(name = "zimId", value = "刷脸认证唯一标识", paramType = "query", required = true),
			@ApiImplicitParam(name = "userId", value = "用户id", paramType = "query" ,required = true ),
			@ApiImplicitParam(name = "requestSource", value = "请求来源", paramType = "query" ,required = true ) })
	@RequestMapping(value = "/queryFace", method = { RequestMethod.POST })
	@ResponseBody
	public Map<String, Object> query(@RequestBody FaceModel vo) throws InterruptedException {

		if (vo == null || StringUtils.isEmpty(vo.getBizId()) || StringUtils.isEmpty(vo.getZimId())) {
			return ResultUtil.resultMap(CodeUtil.CODE_10000.getName(), CodeUtil.CODE_10000.getCode(), null);
		}
		return faceService.queryFaceService(vo);

	}

}
